from collections import OrderedDict

from rest_framework.pagination import PageNumberPagination

# 自定义分页器
from rest_framework.response import Response


class MyPageNumberPagination(PageNumberPagination):
    page_size = 3  # 每页显示3条数据
    page_size_query_param = 'page_size'
    # page_size_query_description = 'size'
    # max_page_size = 5  # 最大每页显示五条数据

    # 重写方法 修改返回值
    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('count', self.page.paginator.count),
            # ('next', self.get_next_link()),
            # ('previous', self.get_previous_link()),
            ('results', data)
        ]))

